{include file="public/meta" /}
<title>编辑产品 - 产品管理</title>
<body>
<article class="page-container">
    <form class="form form-horizontal" id="form-goods-edit">
        <input type="hidden" name="id" value="{$info['id']}">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>产品标题：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="输入产品标题" id="title" name="title" value="{$info['title']}">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>产品编号：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" placeholder="" id="goods_no" name="goods_no" value="{$info['goods_no']}">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>产品分类：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="select-box">
				<select name="category_id" id="category_id" class="select">
					<option value="0">请选择产品分类</option>
					{volist name="categoryList" id="val"}
					<option value="{$val['id']}" {if condition="$info['category_id'] eq $val['id']"}selected{/if}>{$val['title']}</option>
					{/volist}
				</select>
				</span>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>封面图：</label>
            <div class="formControls col-xs-8 col-sm-9"> <span class="btn-upload form-group">
				<input class="input-text upload-url" type="text" name="img_url" id="img_url" nullmsg="请添加图片" style="width:400px" value="{$info['img_url']}">
				<a href="javascript:void(0);" class="btn btn-primary radius upload-btn"><i class="Hui-iconfont">&#xe642;</i> 封面图</a>
				<input type="file" name="file-1" class="input-file" id="img-url-file">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>图片集：</label>
            <div class="formControls col-xs-8 col-sm-9">
                    <div class="uploadbtn">
                        <a id="btn"></a>
                    </div>
                    {volist name="$imgList" id="val"}
                    <div class='upimg_box'>
                        <img src="{$val['img_url']}" style="height:108px;" />
                        <div class='sctxt'>
                            <a href='javascript:void(0);' onclick='test(this)' bindImageUrl="{$val['img_url']}">删除</a>
                        </div>
                        <input type="hidden" name="images[]" value="{$val['img_url']}">
                    </div>
                    {/volist}
                    <ul id="ul_pics" class="ul_pics clearfix"></ul>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>销售价格：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$info['sell_price']}" placeholder="" id="sell_price" name="sell_price">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>市场价格：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$info['market_price']}" placeholder="" id="market_price" name="market_price">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>商品库存：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$info['stock']}" placeholder="" id="stock" name="stock">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>显示状态：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="radio" class="sorting_disabled" value="0" name="status" {eq name="$info.status" value="0"}checked{/eq}>上架
                <input type="radio" class="sorting_disabled" value="1" name="status" {eq name="$info.status" value="1"}checked{/eq}>下架
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>推荐类型：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="checkbox" class="sorting_disabled" value="1" placeholder="" id="is_rec" name="is_rec" {eq name="$info.is_rec" value="1"}checked{/eq}>推荐
                <input type="checkbox" class="sorting_disabled" value="1" placeholder="" id="is_top" name="is_top" {eq name="$info.is_top" value="1"}checked{/eq}>置顶
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>排序：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="{$info['sort']}" placeholder="" id="sort" name="sort">
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">商品描述：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <textarea id="content" name="content" style="width:100%;height:400px;">{$info['content']}</textarea>
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <button onClick="goods_edit();" class="btn btn-primary radius" type="button"><i class="Hui-iconfont">&#xe632;</i> 保存提交</button>
                <button onClick="removeIframe();" class="btn btn-default radius" type="button">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>

</article>

<!--_footer 作为公共模版分离出去-->
{include file="public/footer" /}
<!--/_footer /作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/ueditor.config.js"></script>
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/ueditor.all.min.js"> </script>
<script type="text/javascript" src="__LIB__/ueditor/1.4.3/lang/zh-cn/zh-cn.js"></script>
<script src="__LIB__/plupload.full.min.js"></script>

<script type="text/javascript">
    //创建实例的构造方法
    var uploader = new plupload.Uploader({
        runtimes: 'html5,flash,silverlight,html4',
        browse_button: 'btn',
        url: "{:url('Common/upload')}",
        flash_swf_url: 'plupload/Moxie.swf',
        silverlight_xap_url: 'plupload/Moxie.xap',
        filters: {
            max_file_size: '2mb', //最大上传文件大小（格式100b, 10kb, 10mb, 1gb）
            mime_types: [//允许文件上传类型
                {title: "files", extensions: "jpg,png,gif"}
            ]
        },
        multi_selection: true, //true:ctrl多文件上传, false 单文件上传
        init: {
            FilesAdded: function(up, files) { //文件上传前
                if ($("#ul_pics").children("li").length > 30) {
                    alert("您上传的图片太多了！");
                    uploader.destroy();
                } else {
                    var li = '';
                    plupload.each(files, function(file) { //遍历文件
                        li += "<li id='" + file['id'] + "'><div class='progress'><span class='bar'></span><span class='percent'>0%</span></div></li>";
                    });
                    $("#ul_pics").append(li);
                    uploader.start();
                }
            },
            UploadProgress: function(up, file) { //上传中，显示进度条
                $("#" + file.id).find('.bar').css({"width": file.percent + "%"}).find(".percent").text(file.percent + "%");
            },
            FileUploaded: function(up, file, info) { //文件上传成功的时候触发
                var data = JSON.parse(info.response);
                $("#" + file.id).html("<div class='upimg_box'> <img src='" +
                    data.data + "'/><div class='sctxt'><a href='javascript:void(0);' bindImageUrl='"+
                    data.data+"' onclick='test(this)'>删除</a></div><input type='hidden' name='images[]' value="+
                    data.data +"></div>");

            },
            Error: function(up, err) { //上传出错的时候触发
                alert(err.message);
            }
        }
    });
    uploader.init();
    function test(obj){
        var bindImageUrl = $(obj).attr('bindImageUrl');
        $(obj).parent().parent().css('display','none')
        $(obj).parent().next().removeAttr('name');
        // $.post(
        //     "{:url('Common/imageDel')}",
        //     {'imageUrl':bindImageUrl},
        //     function (data) {
        //         if ( data != 1 ){
        //             layer.msg('删除失败');
        //         }
        //     },'json'
        // );
    }
</script>
<script type="text/javascript">
    $(function(){
        $('.skin-minimal input').iCheck({
            checkboxClass: 'icheckbox-blue',
            radioClass: 'iradio-blue',
            increaseArea: '20%'
        });

        var ue = UE.getEditor('content');

    });
    //单图片上传
    $('#img-url-file').change(function(){
        var filess=$('#img-url-file')[0].files[0]
        console.log(filess);
        var fm=new FormData();
        fm.append('image',filess);

        $.ajax({
            type: 'post',
            url: "{:url('Common/uploadImage')}",
            data: fm,
            processData: false,
            contentType: false,
            success: function(data) {
                //alert(data);
                var jdata=JSON.parse(data);
                if(jdata.code==0)
                {
                    parent.layer.msg(jdata.msg,{icon:6,time:1000});
                    var imgurl=jdata.data;
                    imgurl= imgurl.replace(/\\/g, "/");
                    $('#img_url').val(imgurl);
                }
                else {
                    parent.layer.msg(jdata.msg,{icon:5,time:1000});
                }

            },
            error:function(data){
                layer.msg('500系统错误，请重试！',{icon:5,time:1000});
            }
        });
    });
    function goods_edit(){
        var form = $("#form-goods-edit").serializeArray();
        $.ajax({
            url:"{:url('Integral/edit')}",
            type:"post",
            data:form,
            dataType:"json",
            success:function(data){
                if(data.code==0)
                {
                    parent.layer.msg(data.msg,{icon:6,time:1000});
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.window.location.reload();
                    parent.layer.close(index);
                }
                else
                {
                    parent.layer.msg(data.msg,{icon:5,time:1000});
                    var index = parent.layer.getFrameIndex(window.name);
                    parent.layer.close(index);
                }
            },
            error:function(data){
                layer.msg('500系统错误，请联系管理员！',{icon:5,time:1000});
            }
        });
    }
</script>
<!--/请在上方写此页面业务相关的脚本-->
</body>
</head>

</html>